package com.handpay.nocardpay.baselibrary.raindrops.presenter;

import android.content.Context;

import com.handpay.nocardpay.baselibrary.commbase.model.IBaseModel;
import com.handpay.nocardpay.baselibrary.commbase.model.bean.BaseErrorInfo;
import com.handpay.nocardpay.baselibrary.commbase.presenter.IBasePresenter;
import com.handpay.nocardpay.baselibrary.raindrops.model.IRainDropsModel;
import com.handpay.nocardpay.baselibrary.raindrops.model.bean.AuthResult;
import com.handpay.nocardpay.baselibrary.raindrops.model.impl.RainDropsModeImpl;
import com.handpay.nocardpay.baselibrary.raindrops.view.IAuthView;

import java.util.Map;

/**
 * Created by sxshi on 2018-4-23.
 */

public class RainDropsPresenterImpl implements IBasePresenter {

    IRainDropsModel<AuthResult> authModel;

    IAuthView authView;

    private Context mContext;

    public RainDropsPresenterImpl(Context mContext) {
        this.mContext = mContext;
        authModel = new RainDropsModeImpl(mContext);
    }

    public void setAuthView(IAuthView authView) {
        this.authView = authView;
    }

    public void getAuthResult(String path, Map<String, Object> paramers, boolean isShowLoading) {
        if (authView != null) {
            if (isShowLoading) {
                authView.showProgress();
            }
        }

        authModel.getAuthStatus(path, paramers, AuthResult.class, new IBaseModel.OnRequestFinishedListener<AuthResult>() {
            @Override
            public void onError(BaseErrorInfo baseErrorInfo) {
                if (authView != null) {
                    authView.hideProgress();
                    authView.showErrorAlert(baseErrorInfo);
                }
            }

            @Override
            public void onSuccess(AuthResult response) {
                if (authView != null) {
                    authView.hideProgress();
                    authView.getAuthResult(response);
                }
            }
        });
    }

    public void noticeUpload(String path,Map<String,Object>param){
        authModel.noticeUpload(path,param);
    }
    @Override
    public void onDestory() {
        if (authView != null) {
            authView = null;
        }
        if (authModel != null) {
            authModel = null;
        }
    }
}
